package com.sky.controller.admin.dish;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 42
 * @date 2025/3/25
 * @Description 菜品分类接口
 */

@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api(tags="菜品接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dishDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result add(@RequestBody DishDTO dishDto){
        log.info("新增菜品:{}",dishDto);
        return dishService.add(dishDto);
    }

    /**
     * 菜品分页
     * @param queryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页")
    public Result<PageResult> page(DishPageQueryDTO queryDTO){
        log.info("菜品分页:{}",queryDTO);
        return dishService.page(queryDTO);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result deleteBatch(@RequestParam List<Long> ids){
        log.info("批量删除菜品:{}",ids);
        return dishService.deleteBatch(ids);
    }

    /**
     * 根据id查询菜品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品信息")
    public Result<DishVO> selectDishInfo(@PathVariable Long id){
        log.info("根据id查询菜品信息:{}",id);
        return dishService.selectDishInfo(id);
    }

    /**
     * 修改菜品
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDishInfo(@RequestBody DishDTO dishDTO){
        log.info("修改菜品:{}",dishDTO);
        return dishService.updateDishInfo(dishDTO);
    }

    /**
     * 起售或禁售菜品
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result startOrStop(Long id,@PathVariable Integer status){
        log.info("起售或禁售商品,id:{},status:{}",id,status);
        return dishService.startOrStop(id,status);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId){
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list);
    }

}
